package com.liveims.webims.util;

/*
 * This class is to modelize the RESTful 'webims' URIs, like:
 * /+33618757120/profile...
 * It offers methods to parser the uri path, which may be useful to route the http request to HttpServlet
 */
public class RestPath {
	
   private static final String PATH_SEPERATOR = "/";
   
   final String paths[];
   final static String SERVICE_PATH = "services";
   final static String PROFILE_PATH = "profile";
   final static String CONTACT_PATH = "contacts";
   final static String PRESENCE_PATH = "presence";
   final static String IM_PATH = "im";
   
   public RestPath(String path){
	   this.paths = path.split(PATH_SEPERATOR);
   }
   
   public String getIMPU(){
       if (paths.length >0) 	  
	      return paths[1];
       else
    	  return null;
   }
   
   public String getSessionID(){
	  if (paths.length > 3) 
	     return paths[3];
	  else
		 return null;
   }
   
   public boolean isForProfile(){
	  if (paths.length > 2 && paths[2].equalsIgnoreCase(PROFILE_PATH))
	    return true;
	  else
		return false;
   }
   
   public boolean isForContacts(){
	  if (paths.length > 2 && paths[2].equalsIgnoreCase(CONTACT_PATH))
		 return true;
	  else
	     return false;
	   
   }
   
   public boolean isForPresence(){
	   if (paths.length > 2 && paths[2].equalsIgnoreCase(PRESENCE_PATH))
		    return true;
	    else
			return false;	   
   }
   
   public boolean isForServices(){
	   if (paths.length > 2 && paths[2].equalsIgnoreCase(SERVICE_PATH))
		   return true;
	   else
		   return false;	   
   }
   public boolean isForIM(){
	   if (paths.length > 2 && paths[2].equalsIgnoreCase(IM_PATH))
		   return true;
	   else
		   return false;
	   
   }
   
   public static void main (String[] args){
	   RestPath p = new RestPath("/qian/contacts/");
	   System.out.println(p.getIMPU());
	   System.out.println(p.isForContacts());
	   System.out.println(p.paths.length);
	   
   }
}
